package greed;

import java.util.Arrays;

/**
 * @Classname : NonOverlappingIntervals
 * @Description : 435. 无重叠区间
 * https://leetcode.cn/problems/non-overlapping-intervals/
 * @Author : chentianyu
 * @Date 2023/2/24 00:05
 */


public class NonOverlappingIntervals {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, (o1, o2)->Integer.compare(o1[1], o2[1]));
        int ans = 0, last = intervals[0][1];
        for (int i=1; i<intervals.length; i++) {
            if (intervals[i][0] < last) {
                ans++;
            } else {
                last = intervals[i][1];
            }
        }
        return ans;
    }
}
